package com.order.config;


import com.order.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 * 用于注册拦截器，并配置拦截规则
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    // 注入权限拦截器
    @Autowired
    private AuthInterceptor authInterceptor;

    /**
     * 注册拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册权限拦截器
        registry.addInterceptor(authInterceptor)
        // 排除文件下载接口，不拦截
                // 配置拦截所有路径
                .addPathPatterns("/**")
                // 配置不拦截的路径（登录、注册接口不需要登录即可访问）
                .excludePathPatterns(
                        "/user/login",    // 登录接口
                        "/user/register",
                        "/files/download/**",
                        "/sell/**",
                        "/api/**",
                        "/statistics/**"
                );
    }
}
    